﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Group3.MediaTool.Interface;
using System.IO;
using Group3.MediaTool.Data.IO;

namespace Group3.MediaTool.Provider
{
    public class Dal
    {        
        public static DataStoreProvider GetProvider()
        {
            e_DataStoreProvider provider;
            string connectionstring, database;
            Dal.ReadProviderConfig(out provider, out connectionstring, out database);
            switch (provider)
            {
                case e_DataStoreProvider.NDatabase:
                    return new NDatabaseProvider() { StoreProvider = provider, Connect = connectionstring, Store = database };    
                case e_DataStoreProvider.MSSQLServer:
                    return new SQLDatabaseProvider() {StoreProvider = provider, Connect = connectionstring, Store = database };
                default:
                    return null;
            }
        }

        private static void ReadProviderConfig(out e_DataStoreProvider provider, out string connectionstring, out string database)
        {
            switch(StaticConfig.Database)
            {
                case e_DataStoreProvider.NDatabase: 
                    provider = e_DataStoreProvider.NDatabase;
                    connectionstring = Path.Combine(StaticConfig.pathDataDefinition, "Database");
                    database = "Test.db";
                    break;
                case e_DataStoreProvider.MSSQLServer:
                    provider = e_DataStoreProvider.MSSQLServer;
                    connectionstring = StaticConfig.databaseConnection;
                    database = "";
                    break;
                default:
                    provider = e_DataStoreProvider.FLATFILE;
                    connectionstring = "";
                    database = "";
                    break;
            }
            
        }
    }
}
